package com.atguigu.eduservice.controller;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduVideo;
import com.atguigu.eduservice.service.EduVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author lgy
 * @since 2022-04-13
 */
@RestController
@RequestMapping("/eduservice/edu-video")
//@CrossOrigin //解决跨域问题
@Api(description="小节管理")
public class EduVideoController {

    @Autowired
    private EduVideoService eduVideoService;

    //添加小节
    @ApiOperation(value = "添加小节")
    @PostMapping("/addVideo")
    public R addVideo(@RequestBody EduVideo eduVideo){
        eduVideoService.save(eduVideo);
        return R.ok();
    }

    //修改小节
    @ApiOperation(value = "修改小节")
    @PostMapping("/updateVideo")
    public R updateVideo(@RequestBody EduVideo eduVideo){
        eduVideoService.updateById(eduVideo);
        return R.ok();
    }

    //根据小节id查询
    @ApiOperation(value = "根据小节id查询")
    @GetMapping("/getVideoById/{videoId}")
    public R getVideoById(@PathVariable String videoId){
        EduVideo eduVideo = eduVideoService.getById(videoId);
        return R.ok().data("video",eduVideo);
    }

    //删除小节，删除单个小节，如果小节还有，就删不了章节
    @ApiOperation(value = "删除小节")
    @DeleteMapping("/deleteVideoByid/{id}")
    public R deleteVideoByid(@PathVariable String id){
        R r = eduVideoService.removeVideoIdAndAliyun(id);
        return r;
    }



}


